package com.administrator.customviewtest.paint_view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Environment;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.administrator.customviewtest.R;

import java.io.File;

/**
 * Created by Administrator on 2016/12/29.
 */

public class PaintView extends View {
    private Paint paint;
    private Canvas canvas;


    public PaintView(Context context) {
        this(context, null);
    }

    public PaintView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PaintView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        initPaint();
    }

    private void initPaint() {
        paint = new Paint();
        paint.setColor(Color.GREEN);
        paint.setStyle(Paint.Style.STROKE);
        // 加载画画板的背景图

        // 创建图片副本
        // 1.在内存中创建一个与原图一模一样大小的bitmap对象，创建与原图大小一致的白纸
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                Log.e("ssss", "down");
                canvas.drawCircle(event.getX(), event.getY(), 50, paint);
                invalidate();
                return true;
            }
        }
        return super.onTouchEvent(event);
    }

    @Override
    public void draw(Canvas canvas) {
        canvas.drawCircle(50, 50, 50, paint);
        super.draw(canvas);
    }
}
